package com.droidlogic.mboxlauncher;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.List;

public class RocketActivity extends Activity {
    private AnimationDrawable fireAnimationDrawable;
    /* access modifiers changed from: private */
    public ImageView iv_cloud;
    /* access modifiers changed from: private */
    public ImageView iv_cloud_line;
    /* access modifiers changed from: private */
    public ImageView iv_rocket;
    private RelativeLayout rl_cloud;

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rocket);
        findView();
        initView();
        clearMemory();
    }

    private void findView() {
        this.iv_rocket = (ImageView) findViewById(R.id.iv_rocket);
        this.iv_cloud = (ImageView) findViewById(R.id.iv_cloud);
        this.iv_cloud_line = (ImageView) findViewById(R.id.iv_cloud_line);
        this.rl_cloud = (RelativeLayout) findViewById(R.id.rl_cloud);
    }

    private void initView() {
        this.iv_rocket.setPressed(true);
        this.iv_rocket.setFocusable(true);
        this.iv_rocket.setVisibility(View.VISIBLE);
    }

    /* access modifiers changed from: protected */
    public void onStart() {
        super.onStart();
        this.iv_rocket.setBackgroundResource(R.drawable.rocket_fire);
        this.fireAnimationDrawable = (AnimationDrawable) this.iv_rocket.getBackground();
        this.fireAnimationDrawable.start();
        fly();
    }

    private void fly() {
        Log.e("RocketActivity", "fly....");
        Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rocket_up);
        animation.setFillAfter(true);
        animation.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
                AlphaAnimation cloudAppearAnimation = new AlphaAnimation(0.1f, 1.0f);
                cloudAppearAnimation.setDuration(500);
                Animation appearAnimation = new AlphaAnimation(0.0f, 1.0f);
                appearAnimation.setDuration(500);
                appearAnimation.setStartOffset(250);
                RocketActivity.this.iv_cloud.startAnimation(cloudAppearAnimation);
                RocketActivity.this.iv_cloud_line.startAnimation(appearAnimation);
            }

            public void onAnimationRepeat(Animation animation) {
            }

            public void onAnimationEnd(Animation animation) {
                RocketActivity.this.removeClound();
            }
        });
        this.iv_rocket.startAnimation(animation);
        createClound();
    }

    private void createClound() {
        this.iv_cloud.setVisibility(View.VISIBLE);
        this.iv_cloud_line.setVisibility(View.VISIBLE);
    }

    /* access modifiers changed from: private */
    public void removeClound() {
        AlphaAnimation disappearAnimation = new AlphaAnimation(1.0f, 0.0f);
        disappearAnimation.setDuration(1000);
        disappearAnimation.setFillAfter(true);
        disappearAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        disappearAnimation.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
            }

            public void onAnimationRepeat(Animation animation) {
            }

            public void onAnimationEnd(Animation animation) {
                RocketActivity.this.iv_rocket.setVisibility(View.GONE);
                RocketActivity.this.iv_cloud.setVisibility(View.GONE);
                RocketActivity.this.iv_cloud_line.setVisibility(View.GONE);
                RocketActivity.this.finish();
            }
        });
        this.rl_cloud.startAnimation(disappearAnimation);
    }

    private void clearMemory() {
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> infoList = am.getRunningAppProcesses();
        am.getRunningServices(100);
        long beforeMem = getAvailMemory(this);
        Log.d("RocketActivity", "-----------before memory info : " + beforeMem);
        int count = 0;
        if (infoList != null) {
            for (int i = 0; i < infoList.size(); i++) {
                ActivityManager.RunningAppProcessInfo appProcessInfo = infoList.get(i);
                Log.d("RocketActivity", "process name : " + appProcessInfo.processName);
                Log.d("RocketActivity", "importance : " + appProcessInfo.importance);
                if (appProcessInfo.importance > 200) {
                    String[] pkgList = appProcessInfo.pkgList;
                    for (int j = 0; j < pkgList.length; j++) {
                        Log.d("RocketActivity", "It will be killed, package name : " + pkgList[j]);
                        am.killBackgroundProcesses(pkgList[j]);
                        count++;
                    }
                }
            }
        }
        long afterMem = getAvailMemory(this);
        Log.d("RocketActivity", "----------- after memory info : " + afterMem);
        Toast.makeText(this, "clear " + count + " process, " + (afterMem - beforeMem) + "M", Toast.LENGTH_LONG).show();
    }

    private long getAvailMemory(Context context) {
        ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
        ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
        return mi.availMem / 1048576;
    }
}